package com.gzx.bi.modular.attend.mapper;

import com.gzx.bi.modular.attend.entity.GzxProjectAttendance;
import com.gzx.bi.modular.attend.vo.GzxProjectAttendanceVo;
import com.gzx.bi.modular.project.vo.GzxProjectDebtVo;
import com.gzx.tjzy.feign.resp.project.GzxProjectRespDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * 出勤人数
 */
public interface GzxProjectAttendanceMapper extends BaseMapperPlus<GzxProjectAttendance, GzxProjectAttendanceVo> {

    //批量插入
    @Insert({"<script>" ,
            "INSERT IGNORE INTO gzx_project_attendance" +
            "(project_code,project_name,current_day) " +
            "VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "( #{item.projectCode},#{item.projectName},DATE_FORMAT(CURDATE(), '%Y-%m-%d') )" +
            "</foreach>" +
            "</script>"})
    void insertOnDuplicate(List<GzxProjectRespDto> list);

    //获取当天出勤信息
    @Select({"<script>" ,
            "select id,project_name projectName,attend_user attendUser from gzx_project_attendance " +
            " where current_day = DATE_FORMAT(CURDATE(), '%Y-%m-%d')" +
            "</script>"})
    List<GzxProjectAttendanceVo> listCurrentAttendance();

    //获取当天某个项目的出勤信息
    @Select("<script>" +
            "select project_code projectCode,attend_user attendUser from gzx_project_attendance " +
            " where current_day = DATE_FORMAT(CURDATE(), '%Y-%m-%d') " +
            " and project_code in "+
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "   #{item.projectCode}" +
            "</foreach>" +
            "</script>")
    List<GzxProjectAttendance> getCurrentAttendance(List<GzxProjectDebtVo> list);
}
